//
//  YWClassifyTool.m
//  YueshengToutiao
//
//  Created by jun peng on 2022/2/19.
//  Copyright © 2022 YW. All rights reserved.
//

#import "YWClassifyTool.h"

@implementation YWClassifyTool

+ (void)getClassifyListStatusesWithParameters:(YWGetNewsListParam *)param success:(void(^)(YWClassifyStatus *status))success failure:(void(^)(NSError *error))failure{
    
    
    
    NSString *url = [NSString stringWithFormat:@"%@/api/UserInfo/GetNewsByLabelPage",domainURL];
    
    
    [YWHttpTool Post:url parameters:param.keyValues success:^(id responseObject) {
        
        //        YWLog(@"%@",responseObject);
                
                NSMutableDictionary *dictionary = (NSMutableDictionary *)responseObject;

                id ResultObj = dictionary[@"ResultObj"];

                if ([ResultObj isKindOfClass:[NSNull class]]) {

                    [dictionary setObject:[NSDictionary dictionary] forKey:@"ResultObj"];
                }
                else{
                    
                    id PageInfo = ResultObj[@"PageInfo"];
                    if ([PageInfo isKindOfClass:[NSNull class]]) {
                         [ResultObj setObject:[NSDictionary dictionary] forKey:@"PageInfo"];
                    }
                    else{
                        
                        id nList = PageInfo[@"nList"];
                        if ([nList isKindOfClass:[NSNull class]]) {
                             [PageInfo setObject:[NSArray array] forKey:@"nList"];
                        }
                        else{
                            
                            NSArray *nListArray = (NSArray *)nList;
                            for (NSMutableDictionary *dataDic in nListArray) {
                                
                                id ArrImg = dataDic[@"ArrImg"];
                                if ([ArrImg isKindOfClass:[NSNull class]]) {
                                     [dataDic setObject:[NSArray array] forKey:@"ArrImg"];
                                }
                                
                            }
                            
                        }
                        
                        
//                        id ArrImg = PageInfo[@"ArrImg"];
//                        if ([ArrImg isKindOfClass:[NSNull class]]) {
//                             [PageInfo setObject:[NSArray array] forKey:@"ArrImg"];
//                        }
                        
                    }
                   
                }
         
         //试用这个方法、但是最多只能将原来是string类型返回null有效、但是对于原来是NSDictionary或者array类型的返回null但是转为了@“”依然会奔溃的 (所以我选择了与上面代码一起配合)
         NSDictionary *dic = [NSDictionary nullDic:dictionary];
       
        YWClassifyStatus *status = [YWClassifyStatus objectWithKeyValues:dic] ;
        
        
        // 传递了block
        if (success) {
            success(status);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
        
    }];
    
    
    
}
@end
